import nami from '/nami/index';

App({
  data: {
    userInfo: null,
    diaryID: null 
  },

  onLaunch: function () {
    var app = this;
    //登录
    nami.login(() => {
      nami.getUserInfo((userInfo) => {
        nami.request({
          url: '/request/diary/login.groovy',
          success: function (res) {
            console.log("已获取数据", userInfo);
            app.data.userInfo = userInfo;
            nami.request({
              url: '/request/diary/addDiary.groovy',
              success: function (res) {
                console.log('id:', res.data);
                app.data.diaryID = res.data.ID;
                wx.setStorage({
                  key: "diaryID",
                  data: res.data.ID
                });
              }
            });
          }
        });
      }, () => {
        console.log("用户拒绝提供信息");
      });
    });

  }
})